<template>
  <div>
    <div class="card-view _p-20 disFlxJS">
      <div>
        <h6 style="margin-bottom: 0;font-weight: bolder;">资源平台跨界合作开关</h6>
        <div class="tips _mt-5">默认关闭，开启后则两个机构合作时可选择资源平台合作，合作后则可互相推广产品服务。</div>
      </div>
      <a-switch :checked="isChecked" :defaultChecked="isChecked" @change="handleChangeIsOpen" />
    </div>
    <div class="card-view _p-20 disFlxJS _mt-30">
      <div style="width: 50%">
        <h6 style="margin-bottom: 0;font-weight: bolder;">
          合作机构服务费分润（从本机构资源平台服务费中按百分比分润）
        </h6>
        <p class="tips _mt-5">
          资源平台服务费由机构抽取，如机构又将会员的产品推广给合作机构，则由机构从抽取的服务费中再按比例分配给合作机构作为合作机构推广的服务费
        </p>
        <p class="tips">
          例如：订单单价：¥100.00，本机构资源平台服务费：¥20.00，则合作机构服务费分润=¥20.00×服务费分润百分比
        </p>
      </div>
      <div>
        <a-input-number v-model="percent" :min="0" placeholder="请输入" style="width: 100px;" />
        <span class="_ml-10">%</span>
      </div>
    </div>
    <div  class="disFlxCC _mt-20">
      <a-button type="primary" size="large" style="width: 200px" @click="handleTenantSave">保存</a-button>
    </div>
  </div>
</template>

<script>
import { orgGetTenantInfoByProjectType, orgTenantOneSave } from '@/api/system/base'

export default {
  components: {},
  data() {
    return {
      projectType: 3,
      /** 是否开启 */
      isOpen: 0,
      /** 分润比例 */
      percent: 0
    }
  },
  computed: {
    isChecked() {
      return this.isOpen === 0;
    }
  },
  watch: {},
  methods: {
    handleChangeIsOpen(val) {
      this.isOpen = val ? 0 : 1
    },
    handleTenantSave() {
      orgTenantOneSave({ projectType: this.projectType, percent: this.percent, isOpen: this.isOpen }).then(
        ({ code, msg }) => {
          if (code === 90001) {
            Modal.confirm({
              title: '提示',
              content: msg,
              cancelText: '暂不开通',
              okText: '去开通',
              onCancel: () => { },
              onOk: () => {
                this.$router.push({
                  path: '/system/paySettings',
                  query: {
                    titleKey: 'onlinePayment'
                  }
                })
              }
            })
          } else if (code === 0) {
            this.$message.success('保存成功')
          }
        }
      )
    }
  },
  created() {
    orgGetTenantInfoByProjectType(this.projectType).then(r => {
      if (!r.code && r.data) {
        const res = r.data
        this.percent = res.percent
        this.isOpen = res.isOpen
      }
    })
  },
  mounted() { }
}
</script>

<style lang="less" scoped></style>
